package com.briup.web.controller;

import com.briup.bean.User;
import com.briup.service.UserService;
import com.briup.util.JwtUtils;
import com.briup.util.MD5Util;
import com.briup.util.Result;
import com.briup.vo.LoginParam;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @BelongsProject: cms
 * @BelongsPackage: com.briup.web.controller
 * @Author: li
 * @CreateTime: 2024-11-20  09:27
 * @Description: TODO
 * @Version: 1.0
 */
@Api(tags = "登录模块")
@RestController
public class LoginController {
    @Autowired
    UserService userService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginParam param){
        User user = userService.login(param.getUsername(), MD5Util.MD5(param.getPassword()));
        Map<String, Object> map = new HashMap<>();
        map.put("userId",user.getId());
        map.put("username",user.getUsername());
        map.put("roleId",user.getRoleId());
        String s = JwtUtils.generateJwt(map);
        return Result.success(s);
    }

    @ApiOperation("用户登出")
    @PostMapping("logout")
    public Result logout(){
        return  Result.success();
    }
}
